

local data = load_excel('存档数据.xlsx','天赋点挑战')
local list = {}
for _,da in ipairs(data) do
    local name = da['名称']
    da.tip = da['效果']
    ac.lni('skill',name,da)
    table.insert(list,name)
end

for _, name in ipairs(list) do
    local mt = ac.skill[name]

    function mt:on_add()
        local hard = ac.enemy and ac.enemy.hard or 0
        if self['难度']>hard then
            self:set_enable(false)
        end
    end
    
    function mt:on_cast_shot()
        local hero = self.owner
        local player = hero.owner
        local name = self['怪物']
        if player:get_data(name) then
            return
        end
        player:set_data(name,true)
        local point1 = player.cd_point
        local point2 = player.cd_point - {90,600}
        local unit = ac.player[12]:create_unit(name,point2,270)
        local time = 30
        unit:set_enemy_level(unit['默认等级'])
        unit:issue_order('attack',point1)
        unit:loop(1000,function(t)
            if time<=0 then
                unit:remove()
                player:set_data(name,nil)
                t:remove()
            end
            unit.ui_title = ('%s(|cffffff00%s|r)'):format(name,time)
            time = time - 1
        end):on_timer()
        unit:event '单位-死亡'(function()
            player:send_cloud('击败天赋Boss',name)
            self:remove()
        end)
    end
end


ac.game:event '游戏-游戏胜利'(function()
    ac.each_player(function(player)
        local point = player.cd_point
        local unit = player:create_unit('个人挑战',point,270)
        for _, name in ipairs(list) do
            unit:add_skill(name,'英雄')
        end
    end)
end)
